<?php
/**
 * User:ayou chow
 * Date: 2019-12-06
 * Time: 10:34
 */

namespace app\common\model;


use think\Model;

class UserLevelRuleModel extends Model
{

    static function delUserLevelCache()
    {
        redis_del("USER:LEVEL:RULE");
    }

    static function getUserLevel($point)
    {
        $level = 0;
        if ($point < 1) {
            return $level;
        }

        $level_list = UserLevelRuleModel::order('level ASC')->select();

        foreach ($level_list as $level_info) {
            if ($point == $level_info->point) {
                $level = $level_info->level;
                break;
            }

            if ($point > $level_info->point) {
                $level = $level_info->level;
            }

            foreach ($level_list as $level_two) {
                if ($point == $level_two->point) {
                    $level =  $level_two->level;
                    break;
                }else if ($point >= $level_info->point && $point < $level_two->point) {
                    $level =  $level_info->level;
                    break;
                }
            }
        }
        return $level;
    }

}